package com.xiangyang.controller;

import com.xiangyang.entity.Post;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.mapper.IPostMapper;
import com.xiangyang.service.impl.PostServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.xiangyang.entity.vo.PostInfoPage;

@RestController
@RequestMapping("/Post")
@CrossOrigin
public class PostController {
    @Autowired
    private PostServiceImpl ipsi;
    @Autowired
    private IPostMapper ipm;


    @PostMapping("/addPost")
    @PreAuthorize("hasAnyAuthority('sys:employee')")// 添加岗位
    public Result addPost(@RequestBody Post post) {

        return ipsi.addPost(post);
    }

    @DeleteMapping("/deletePost")
    @PreAuthorize("hasAnyAuthority('sys:employee')")// 删除岗位
    public Result deletePost(Long postId) {

        return ipsi.deletePost(postId);
    }

    @GetMapping("/getPostList")         // 获取岗位列表
    public Result getPostList() {
        return ipsi.getPostList();
    }

    @PutMapping("/updatePost")
    @PreAuthorize("hasAnyAuthority('sys:employee')")// 更新岗位
    public Result updatePost(@RequestBody Post post) {
        return ipsi.updatePostById(post);
    }
    @GetMapping("/getPostList/{pageNum}/{pageSize}")        // 分页查询
    public Result<Object> getPostList(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        return ipsi.getPostList(pageNum,pageSize);
    }
    @PostMapping ("/selectPost")
    public Result selectPost(@RequestBody  PostInfoPage post) {
        return ipsi.selectPostInfo(post);
    }
}